package com.example.myapplication.ui.notifications;

import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import android.app.Fragment;
import android.widget.Toast;

import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction;
import androidx.lifecycle.Observer;
import androidx.lifecycle.ViewModelProvider;

import com.example.myapplication.LoginActivity;
import com.example.myapplication.R;
import com.example.myapplication.RegisterActivity;
import com.example.myapplication.dao.ConfirmDao;

public class LoginedFragment extends Fragment {


    public View onCreateView(@NonNull LayoutInflater inflater,
                             ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_login, container, false);
        TextView textView1 = view.findViewById(R.id.tv_QQReadername);
        textView1.setText("你好，" + ConfirmDao.username);
        TextView textView = view.findViewById(R.id.tv_logout);
        textView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                AlertDialog.Builder myDialog=new AlertDialog.Builder(getContext());
                myDialog.setTitle("提示");
                myDialog.setMessage("确定退出登录？");
                myDialog.setNegativeButton("取消",null);
                myDialog.setPositiveButton("确定", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        Toast.makeText(getContext(),"退出成功",Toast.LENGTH_SHORT).show();
                        ConfirmDao.islogin = false;
                        getFragmentManager().beginTransaction().replace(R.id.host_fragment, new NotificationsFragment()).commit();
                    }
                });
                AlertDialog alertDialog=myDialog.create();
                alertDialog.show();




            }
        });
        return view;
    }

}